<!--
	作者：939868405@qq.com
	时间：2018-09-25
	描述：差异调整申请
	应付员测试帐号：102631 111111
	订单号：8100028053 8100028554
-->
<template>
	<div class="m-view-adjustBill m-window">
		<div class="m-condition">
            <el-row :gutter="10">
                <el-col :span="2" :offset="10">
					<el-radio :disabled="radio_Disabled" v-model="radio" label="0" @change="changeRa">显示启用</el-radio>
				</el-col>
				<el-col :span="2">
					<el-radio :disabled="radio_Disabled" v-model="radio" label="1" @change="changeRa">显示禁用</el-radio>
				</el-col>
				<el-col :span="2">
					<el-button type="primary" @click="search">查询</el-button>
				</el-col>
				<el-col :span="2">
                    <el-button type="primary" @click="add" :disabled="btn_add_Disabled">新增</el-button>
				</el-col>
				<el-col :span="2">
					<el-button type="primary" @click="edit" :disabled="btn_edit_Disabled">浏览</el-button>
				</el-col>
				<el-col :span="2">
					<el-button type="primary" @click="reuse" :disabled="btn_reuse_Disabled">启用</el-button>
				</el-col>
				<el-col :span="2">
					<el-button type="primary" @click="del" :disabled="btn_del_Disabled">停用</el-button>
				</el-col>
			</el-row>
			<el-row :gutter="10">
				<el-form
					:model="headerRuleForm"
					ref="headerRuleForm"
					label-width="70px"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="6">
						<el-form-item label="订单号" class="rightItem">
							<el-input v-model="purOrdNo" placeholder="请输入订单号" clearable @keyup.enter.native="search"></el-input>
						</el-form-item>
					</el-col>
                    <el-col :span="7">
						<el-form-item label="申请日期" class="rightItem">
							<el-date-picker
								v-model="applySDate"
								type="date"
								placeholder="开始日期"
								value-format="yyyy-MM-dd"
							></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-date-picker v-model="applyEDate" type="date" placeholder="结束日期" value-format="yyyy-MM-dd"></el-date-picker>
					</el-col>
					<el-col :span="5">
						<el-form-item label="单据状态" class="rightItem">
							<el-select v-model="state" placeholder="单据状态" value-key="value" @change="changeOp">
								<el-option
									v-for="item in recOptions"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>

		<div class="m-agTable m-top2 m-bottom">
			<ag-grid-vue
				class="m-agTableContent ag-theme-balham"
				:gridOptions="gridOptions"
				:columnDefs="columnDefs"
				:rowData="rowData"
				v-loading="loading"
				rowSelection="multiple"
			></ag-grid-vue>
		</div>

		<!--
    	作者：939868405@qq.com
    	时间：2018-09-25
    	描述：弹框
		-->
		<el-dialog
			class="m-recordTable"
			:title="title"
			:visible.sync="dialogVisible"
			v-if="dialogVisible"
			width="60%"
			v-dialogDrag
			:before-close="handleClose"
			:close-on-click-modal="false"
			:close-on-press-escape="false"
		>
			<el-form
				:model="ruleForm"
				ref="ruleForm"
				label-width="100px"
				class="edit-ruleForm"
				:rules="rules"
			>
				<!--第一行、订单号和行号-->
				<el-row>
					<el-col :span="12">
						<el-form-item label="订单号：" prop="purOrdNo">
							<el-input v-model="ruleForm.purOrdNo" :disabled="in_purOrdNo_dis" @keyup.enter.native="getPurOrdInfo"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="行号：" prop="purOrdMxNo">
							<el-input
								v-model="ruleForm.purOrdMxNo"
								:disabled="in_purOrdMxNo_dis"
								@keyup.enter.native="getPurOrdInfo"
							></el-input>
						</el-form-item>
					</el-col>

					<!--第二行、物料编号和物料描述-->

					<el-col :span="12">
						<el-form-item label="物料编号：" prop="matCode">
							<el-input v-model="ruleForm.matCode" :disabled="true"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="物料描述：" prop="matName">
							<el-input v-model="ruleForm.matName" :disabled="true"></el-input>
						</el-form-item>
					</el-col>

					<!--第三行、订单数量和单位-->

					<el-col :span="12">
						<el-form-item label="订单数量：" prop="orderAmount">
							<el-input v-model="ruleForm.orderAmount" :disabled="true"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="单位：" prop="unitCode">
							<el-input v-model="ruleForm.unitCode" :disabled="true"></el-input>
						</el-form-item>
					</el-col>

					<!--第三行、订单价格数量和价格单位-->

					<el-col :span="12">
						<el-form-item label="价格数量：" prop="orderAmount">
							<el-input v-model="ruleForm.priceAmount" :disabled="true"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="价格单位：" prop="unitCode">
							<el-input v-model="ruleForm.priceUnit" :disabled="true"></el-input>
						</el-form-item>
					</el-col>

					<!--第四行、订单单价和订单金额-->

					<el-col :span="12">
						<el-form-item label="订单单价：" prop="unitPrice">
							<el-input v-model="ruleForm.unitPrice" :disabled="true"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="订单金额：" prop="unitmoney">
							<el-input v-model="ruleForm.unitmoney" :disabled="true"></el-input>
						</el-form-item>
					</el-col>

					<!--第五行、实际单价和实际金额-->

					<el-col :span="12">
						<el-form-item label="实际单价：" prop="realPrice">
							<el-input
								v-model="ruleForm.realPrice"
								:disabled="in_realPrice_dis"
								@keyup.enter.native="getrealMoney"
								@blur="getrealMoney"
							>
								<el-button slot="append" @click="getrealMoney" v-if="false">计算</el-button>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="实际金额：" prop="realMoney">
							<el-input v-model="ruleForm.realMoney" :disabled="true"></el-input>
						</el-form-item>
					</el-col>

					<!--第六行、差异金额-->

					<el-col :span="12">
						<el-form-item label="差异金额：" prop="diffMoney">
							<el-input v-model="ruleForm.diffMoney" :disabled="true"></el-input>
						</el-form-item>
					</el-col>

					<!--第七、八行、备注-->

					<el-col :span="24">
						<el-form-item label="备注：" prop="remark">
							<el-input
								v-model="ruleForm.remark"
								type="textarea"
								:rows="3"
								placeholder="(100字以内)"
								:disabled="in_remark_dis"
							></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<!--第九行、添加附件 -->
				<el-form-item label="附件:">
					<upLoadfile
						:files="files"
						:config="fileConfig"
						@fileChange="fileChange"
						:showBtn="!btn_submit_dis"
                        ref="upload"
					></upLoadfile>
				</el-form-item>
			</el-form>
			<!--底部、取消和保存按钮-->
			<span slot="footer" class="dialog-footer">
				<el-button @click="cancel">取消</el-button>
				<el-button type="primary" :disabled="btn_save_dis" @click="saveData">保存</el-button>
				<el-button type="primary" :disabled="btn_submit_dis" @click="btn_submit">提交</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
import _Api from "@/api";
import localeText from "@/i18n/agGridText";
import Vue from "vue"
import downLoadFileFunc from "@/public/downLoadFile"
import addOperation from "@/public/addOperation"
import upLoadfile from "@/components/upLoadFile";
import gridOptions from 'lesso-common/public/gridOptions';

const details = Vue.extend({
	template: '<el-button type="text" @click="details" class="rendererClass" size="mini">附件名称</el-button>',
	methods: {
		details () {
			//console.log(this.params);
			this.params.context.componentParent.showDifDialog(this.params.node.data);
		}
	}
})

export default {
	data () {

		var check_purOrdNo = (rule, value, callback) => {
			setTimeout(() => {
				if (value) {
					if (value == "") {
						callback(new Error("请输入订单号！"));
					}
					else
						callback();
				} else {
					callback(new Error("请输入订单号！"));
				}
			}, 100);
		};
		var check_purOrdMxNo = (rule, value, callback) => {
			setTimeout(() => {
				if (value) {
					if (value == "") {
						callback(new Error("请输入订单行号！"));
					}
					else
						callback();
				} else {
					callback(new Error("请输入订单行号！"));
				}
			}, 100);
		};
		var check_matCode = (rule, value, callback) => {
			setTimeout(() => {
				if (value) {
					if (!value.trim()) {
						callback(new Error("请输入物料编码！"));
					}
					else
						callback();
				} else {
					callback(new Error("请输入物料编码！"));
				}
			}, 100);
		};
		var check_realPrice = (rule, value, callback) => {
			setTimeout(() => {
				if (value) {
					if (value == "") {
						callback(new Error("请输入实际单价！"));
					}
					else
						callback();
				} else {
					callback(new Error("请输入实际单价！"));
				}
			}, 100);
		};
		var check_realMoney = (rule, value, callback) => {
			setTimeout(() => {
				if (value) {
					if (value == "") {
						callback(new Error("请输入实际金额！"));
					}
					else
						callback();
				} else {
					callback(new Error("请输入实际金额！"));
				}
			}, 100);
		};

		return {
			headerRuleForm: {},
			purOrdNo: "",//采购订单号
			//单据状态
			recOptions: [
				{ value: 0, label: "保存" },
				{ value: 1, label: "提交" },
				{ value: 2, label: "通过" }],
			state: 1,//提交
			applySDate: "",
			applyEDate: "",
			radio: '0',//显示启用
			radio_Disabled: true,
			btn_add_Disabled: false,//新增按钮的可编辑状态
			btn_edit_Disabled: false,//编辑按钮的可编辑状态
			btn_del_Disabled: true,//停用按钮的可编辑状态
			btn_reuse_Disabled: true,//启用按钮的可编辑状态
			dialogVisible: false,//弹出框的可视状态
			rowData: [],//行
			columnDefs: [],//列
			loading: false,//加载

			//弹出框
			title: "",//弹出框的标题
			mode: "",
			fileList: [],//上传文件
			ruleForm: {
				priceAmount: '',
				priceUnit: ''
			},//弹框的数据集
			upload_url: this.$uploadUrl,
			btn_upload_dis: false,
			upload_show: false,
			rules: {//验证规则
				purOrdNo: [{
					required: true,
					validator: check_purOrdNo,
					trigger: "change"
				}],
				purOrdMxNo: [{
					required: true,
					validator: check_purOrdMxNo,
					trigger: "change"
				}],
				// matCode: [{
				// 	required: true,
				// 	validator: check_matCode,
				// 	trigger: "change"
				// }],
				realPrice: [{
					required: true,
					validator: check_realPrice,
					trigger: "change"
				}],
				realMoney: [{
					required: true,
					validator: check_realMoney,
					trigger: "change"
				}],
				remark: [{
					min: 0,
					max: 200,
					triggerr: "change",
					message: "长度在200个字符"
				}]
			},
			in_purOrdNo_dis: false,
			in_purOrdMxNo_dis: false,
			in_realPrice_dis: false,
			in_remark_dis: false,
			btn_save_dis: false,
			btn_submit_dis: false,

			//分页、缓存搜索条件
			tempSearch: {
				purOrdNo: "",
				state: "",
				delFlag: "",
				begin_date: "",
				end_date: ""
			},
			userInfo: {
				userName: this.$global.user.employeeName,
				userId: this.$global.user.id,
				groupName: 'SRM'
			},
			// 上传组件
			//  上传组件相关配置  
			fileConfig: {
				limits: 1,
				accept: '.pdf,.doc,.docx,.xls,.xlsx,.txt',
				maxSize: 20971520,
				multiple: true
			},
			// 回显已上传文件
			files: []
		}
	},

	beforeMount () {
		this.gridOptions = Object.assign({
			context: {
				componentParent: this
			},
			rowSelection: "multiple",
			enableColResize: true,
			localeText: localeText,
			suppressRowClickSelection: true
		}, gridOptions())
		this.columnDefs = [
			{ headerName: "订单号", field: "purOrdNo", width: 125, checkboxSelection: true, headerCheckboxSelection: true, headerCheckboxSelectionFilteredOnly: true },
			{ headerName: "行号", field: "purOrdMxNo", width: 50 },
			{ headerName: "物料描述", field: "matName", width: 250, tooltipField: 'matName' },
			{ headerName: "数量", field: "orderAmount", width: 100 },
			{ headerName: "订单单价", field: "unitPrice", width: 100 },
			{ headerName: "实际单价", field: "realPrice", width: 100 },
			{ headerName: "差异金额", field: "diffMoney", width: 100 },
			{ headerName: "备注", field: "remark", width: 150 },
			{ headerName: "附件名称", field: "attachmentName", width: 150, tooltipField: 'attachmentName' },
			{ headerName: "创建人", field: "creator", width: 100 },
			{ headerName: "创建日期", field: "createDate", width: 150 },
			{ headerName: "提交人", field: "submitter", width: 100 },
			{ headerName: "提交日期", field: "submitDate", width: 150 },
			{ headerName: "审核人", field: "auditor", width: 100 },
			{ headerName: "审核日期", field: "auditDate", width: 150 },
			{				headerName: "单据状态", field: "state", width: 100, cellRenderer: function (params) {
					if (params.value == "0")
						return '<span class="ag-icon">新增</span>';
					else if (params.value == "1")
						return '<span class="ag-icon">提交</span>';
					else if (params.value == "2")
						return '<span class="ag-icon">通过</span>';
				}			},

			{ headerName: "实际金额", field: "realMoney", hide: true },
			{ headerName: "订单金额", field: "unitmoney", hide: true },
			{ headerName: "行号", field: "purOrdMxNo", hide: true },
			{ headerName: "物料号", field: "matCode", hide: true },
			{ headerName: "单位", field: "unitCode", hide: true },
			{ headerName: "id", field: "id", hide: true },
			{ headerName: "附件地址", field: "url", hide: true },
			{ headerName: "审核人ID", field: "auditorId", hide: true },
			{ headerName: "显示标识", field: "delFlag", hide: true },
		];
	},
	mounted () {
		this.search();
	},
	components: {
		upLoadfile
	},
	methods: {
		// 上传文件变化
		fileChange (files) {
			this.fileList = files
			this.files = []
		},
		// 查询列表数据
		search () {
			var obj = {
				eqParams: {},
				likeParams: {},
				geParams: {},
				leParams: {}
			};
			if (this.purOrdNo.replace(/\s+/g, "") == "")
				;
			else
				obj.likeParams.purOrdNo = this.purOrdNo.replace(/\s+/g, "");//去掉文本框里的空格	

			obj.eqParams.state = this.state;

			if (this.state == "0")//保存
				obj.eqParams.delFlag = this.radio;
			else if (this.state == "1")//提交
				obj.eqParams.delFlag = 0;
			else
				obj.eqParams.delFlag = 0;

			//jjc20181014
			if (this.applySDate != "" && this.applySDate != null) {
				obj.geParams.begin_date = this.applySDate;
				if (this.applyEDate == "" || this.applyEDate == null)
					obj.leParams.end_date = obj.geParams.begin_date;
			}
			if (this.applyEDate != "" && this.applyEDate != null) {
				obj.leParams.end_date = this.applyEDate;
				if (this.applySDate == "" || this.applySDate == null)
					obj.geParams.begin_date = obj.leParams.end_date;
			}
			if (obj.geParams.begin_date != "" && obj.leParams.end_date != "") {
				if (obj.geParams.begin_date > obj.leParams.end_date) {
					this.$alert("提示：开始日期不能大于结束日期", {
						showClose: false,
						confirmButtonText: "确定",
						customClass: "alertPrompt"
					});
					return;
				}
			}

			this.saveTempCondition();
			var that = this;
			this.loading = true;
			_Api.getAdjustbill(obj).then(function (respone) {
                that.loading = false
				var data = respone.data;
				if (data.code == "1") {
					if (data.total >= 0) {
						that.gridOptions.api.setRowData(data.rows);
						that.loading = false;
					}
				}
				else {
                    that.loading = false
					that.$alert(data.info, {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					});
				}
			})
        },
        // 新增差异记录
		add () {
			this.title = "新增差异";
			this.mode = "add";
			this.ruleForm = {

            };
			this.dialogVisible = true;
			this.in_purOrdNo_dis = false;
			this.in_purOrdMxNo_dis = false;
			this.in_realPrice_dis = false;
			this.in_remark_dis = false;
			this.btn_save_dis = false;
			this.btn_submit_dis = false;
			this.btn_upload_dis = false;
			this.upload_show = true;

			var that = this;
			// that.$refs.upload.clearFiles();
			this.$nextTick(_ => {
				that.$refs.ruleForm.clearValidate();
			});
        },
        // 修改差异申请记录
		edit () {
			var row = this.gridOptions.api.getSelectedRows();
			//清空
			var that = this;
			if (row.length <= 0) {
				this.$alert("提示：请选择一条想浏览的差异调整！", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"				});
				return;
			}
			else if (row.length > 1) {
				this.$alert("提示：每次只能选择一条想浏览的差异调整！", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"
				});
				return;
			}
			else {
				this.ruleForm = row[0]
				// const {unitPrice,priceAmount,realPrice} = row[0]
				// let unitMoney = addOperation.accMul(unitPrice,priceAmount)
				// this.$set(this.ruleForm, 'unitmoney', unitMoney)
				// let realMoney = addOperation.accMul(realPrice,priceAmount)
				// this.$set(this.ruleForm, 'realMoney', realMoney)
				// let diffMoney = addOperation.accSub(realMoney,unitMoney)
				// this.$set(this.ruleForm, 'diffMoney', diffMoney)
				this.title = "浏览";
				this.mode = "edit";
				this.dialogVisible = true;
				this.$nextTick(_ => {
					that.$refs.ruleForm.clearValidate()
				});
				this.in_purOrdNo_dis = true;
				this.in_purOrdMxNo_dis = true;

				if (this.state == '0') {
					if (this.ruleForm.attachmentName == '')//附件名称
						this.fileList = [];
					else
						this.files = [{
							name: this.ruleForm.attachmentName,
							url: this.ruleForm.url,
							md5: this.ruleForm.md5 || '123',
							iconShow: false
						}
						];
					this.in_realPrice_dis = false;
					this.in_remark_dis = false;
					this.btn_save_dis = false;
					this.btn_submit_dis = false;
					this.btn_upload_dis = false;
					this.upload_show = true;
				}
				// else if (this.state == '1') {
				//   if (this.ruleForm.attachmentName == '')//附件名称
				//     this.fileList = [];
				//   else
				//     this.fileList = [{ name: this.ruleForm.attachmentName, url: this.ruleForm.url }];
				//   this.in_realPrice_dis = true;
				//   this.in_remark_dis = true;
				//   this.btn_save_dis = true;
				//   this.btn_submit_dis = true;
				//   this.btn_upload_dis = true;
				//   this.upload_show = false;
				// }
				else {
					if (this.ruleForm.attachmentName == '')//附件名称
						this.files = []
					else
						this.files = [{
							name: this.ruleForm.attachmentName,
							url: this.ruleForm.url,
							md5: this.ruleForm.md5 || '123',
							iconShow: false
						}]
					this.in_realPrice_dis = true;
					this.in_remark_dis = true;
					this.btn_save_dis = true;
					this.btn_submit_dis = true;
					this.btn_upload_dis = true;
					this.upload_show = false;
				}
			}
		},
		PickDate ({ maxDate, minDate }) {
			//				this.applyDate[0] == minDate;
			//				this.applyDate[1] == maxDate;
		},
		getPurOrdInfo () {
			//检查订单号是否为空
			if (!this.ruleForm.purOrdNo) {
				this.$message({
                    message: '请输入订单号!',
                    type: 'warning'
                });
                return
			}
			//检查订单行号是否为空
			if (!this.ruleForm.purOrdMxNo) {
				this.$message({
                    message: '请输入订单行号!',
                    type: 'warning'
                });
                return
			}

			var obj = {};
			obj.purOrdNo = this.ruleForm.purOrdNo;
			obj.purOrdMxNo = this.ruleForm.purOrdMxNo;
			var that = this;
			_Api.getPurOrdMxOfSap(obj).then(function (response) {
				var data = response.data;
				if (data.code == "1") {
					if (data.total > 0) {
						that.$set(that.ruleForm, 'matCode', data.rows.matCode);
						that.$set(that.ruleForm, 'matName', data.rows.matName);
						that.$set(that.ruleForm, 'orderAmount', data.rows.orderAmount);
						that.$set(that.ruleForm, 'unitCode', data.rows.unitCode);
						that.$set(that.ruleForm, 'unitPrice', data.rows.netPrice);
                        that.$set(that.ruleForm, 'unitmoney', data.rows.netMoney);
                        that.$set(that.ruleForm, 'priceAmount', data.rows.priceAmount);
                        that.$set(that.ruleForm, 'priceUnit', data.rows.priceUnit);
					}
					else {
						that.$message({
							message: "没有此订单行的信息，请检查订单号和行号",
							type: "success"						});
					}
				}
				else {
					that.$alert(data.info, {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"					});
				}
			})
		},
		getrealMoney () {
			//检查实际单价是否为空
			var that = this;
			if (this.ruleForm.realPrice == "" || !this.ruleForm.realPrice) {
				this.$refs["ruleForm"].validate((valid) => {
					if (valid == false) {
						return false;
					}
				});
			}
			if (this.ruleForm.realPrice) {
				this.ruleForm.realPrice = this.ruleForm.realPrice.replace(/[^\d.]/g, '')
				let realMoney = addOperation.accMul(this.ruleForm.realPrice, this.ruleForm.priceAmount);
				that.$set(that.ruleForm, 'realMoney', realMoney);
				let diffMoney = addOperation.accSub(realMoney, this.ruleForm.unitmoney);
				that.$set(that.ruleForm, 'diffMoney', diffMoney);
			}

		},
		del () {
			//
			var row = this.gridOptions.api.getSelectedRows();
			if (row.length <= 0) {
				this.$alert("提示：请选择需要停用的数据", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"				});
				return;
			}
			else {
				var that = this;
				this.$confirm("是否停用数据？", "消息提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					distinguishCancelAndClose: true				})
					.then(() => {
						//
						var id = '';
						for (var i = 0; i < row.length; i++) {
							//						if ()
							id += row[i].id + ',';
						}

						id = id.substr(0, id.length - 1);

						var obj = {
							id: id,
							state: 1,//停用状态
							modifyerId: this.$global.user.id,//修改人ID
							modifyer: this.$global.user.employeeName//修改人
						}
						////editAdjustbillAble
						_Api.editAdjustbillAble(obj).then(function (response) {
							console.log("xx", response);
							var data = response.data;
							if (data.code == "1") {
								that.$message({
									message: "已停用",
									type: "success"								});
								that.search();
							}
							else {
								that.$alert(data.info, {
									showClose: false,
									confirmButton: "确定",
									customClass: "alertFailure"								});
							}

						})
							.catch(() => {
								that.$alert("请求失败！", {
									showClose: false,
									confirmButton: "确定",
									customClass: "alertFailure"								});
							})
					})
					.catch(() => {

					})
			}
		},
		reuse () {
			console.log("启用");

			var row = this.gridOptions.api.getSelectedRows();
			if (row.length <= 0) {
				this.$alert("提示：请选择需要启用的数据", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"				});
				return;
			}
			else {
				var that = this;
				this.$confirm("是否启用数据？", "消息提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					distinguishCancelAndClose: true
				})
					.then(() => {
						var id = '';
						for (var i = 0; i < row.length; i++) {
							//						if ()
							id += row[i].id + ',';
						}

						id = id.substr(0, id.length - 1);

						var obj = {
							id: id,
							state: 0,//启用状态
							modifyerId: this.$global.user.id,//修改人ID
							modifyer: this.$global.user.employeeName//修改人
						}
						_Api.editAdjustbillAble(obj).then(function (response) {
							var data = response.data;
							if (data.code == "1") {
								that.$message({
									message: "已启用",
									type: "success"								});
							}
							else {
								that.$alert(data.info, {
									showClose: false,
									confirmButton: "确定",
									customClass: "alertFailure"								});
							}
							that.search();
						})
							.catch(() => {
								that.$alert("请求失败！", {
									showClose: false,
									confirmButton: "确定",
									customClass: "alertFailure"								});
							})
					})
					.catch(() => {

					})
			}
		},
		changeOp (value) {//选择单据状态

			if (value == 0) {//保存
				this.radio_Disabled = false;
				this.upload_show = true;
				//					this.changeRa(radio);
				if (this.radio == '0')//启用
				{
					this.btn_add_Disabled = false;
					this.btn_edit_Disabled = false;
					this.btn_del_Disabled = false;//停用按钮的可编辑状态
					this.btn_reuse_Disabled = true;//启用按钮的可编辑状态
				}
				else//停用
				{
					this.btn_add_Disabled = true;
					this.btn_edit_Disabled = true;
					this.btn_del_Disabled = true;//停用按钮的可编辑状态
					this.btn_reuse_Disabled = false;//启用按钮的可编辑状态
				}

			}
			//   else if (value == 1) {//提交
			//     this.btn_add_Disabled = false;
			//     this.btn_edit_Disabled = false;
			//     this.radio_Disabled = true;
			//     this.btn_del_Disabled = true;//停用按钮的可编辑状态
			//     this.btn_reuse_Disabled = true;//启用按钮的可编辑状态
			//   }
			else//通过
			{
				this.btn_add_Disabled = false;
				this.btn_edit_Disabled = false;
				this.radio_Disabled = true;
				this.btn_del_Disabled = true;//停用按钮的可编辑状态
				this.btn_reuse_Disabled = true;//启用按钮的可编辑状态
			}
			this.search();
		},
		changeRa (radio) {

			console.log("选择显示启用");
			if (radio == '0')//显示启用
			{
				this.btn_add_Disabled = false;
				this.btn_edit_Disabled = false;
				this.btn_del_Disabled = false;//停用按钮的可编辑状态
				this.btn_reuse_Disabled = true;//启用按钮的可编辑状态
				this.search();
			}
			else//显示禁用
			{
				this.btn_add_Disabled = true;
				this.btn_edit_Disabled = true;
				this.btn_del_Disabled = true;//停用按钮的可编辑状态
				this.btn_reuse_Disabled = false;//启用按钮的可编辑状态
				this.search();
			}
		},
		//保存查询参数
		saveTempCondition () {
			let that = this;
			that.tempSearch.purOrdNo = that.purOrdNo;
			that.tempSearch.state = that.state;
			that.tempSearch.delFlag = that.delFlag;
			that.tempSearch.begin_date = that.begin_date;
			that.tempSearch.end_date = that.end_date;
		},
		//获取查询参数
		getTempCondition () {
			let that = this;
			that.purOrdNo = that.tempSearch.purOrdNo;
			that.state = that.tempSearch.state;
			that.delFlag = that.tempSearch.delFlag;
			that.begin_date = that.tempSearch.begin_date;
			that.end_date = that.tempSearch.end_date;
		},
		//选择分页重新回填数据
		paginationFillCondition (type) {
			this.getTempCondition();
		},
		//处理分页的四个函数
		handleSizeChange (val) {
			this.pageSize = val;
			this.paginationFillCondition(1);
		},
		handleCurrentChange (val) {
			this.currentPage = val;
			this.paginationFillCondition(0);
		},
		handlePrevClick (params) {
			this.currentPage = this.currentPage - 1;
			this.paginationFillCondition(0);
		},
		handleNextClick (params) {
			this.currentPage += 1;
			this.paginationFillCondition(0);
		},

		handleClose (done) {
			var that = this;
			this.$nextTick(_ => {
				that.$refs.ruleForm.clearValidate();
			});
			done();
			this.search();
		},
		submitUpload () {//上传
			this.$refs.upload.submit();
		},
		handleRemove (file, fileList) {

			console.log(file, fileList);
			this.fileList = fileList;
		},
		handlePreview (file) {

			console.log(file.url);
			this.downLoadFile(file);
		},
		handleExceed (file, fileList) {

			this.$message.warning(`最多可添加 1 个附件`);
		},

		beforeRemove (file, fileList) {

		},
		upload_change (file, fileList) {

			this.upload_url = this.$uploadUrl;
			this.filename = file.name;
			this.fileList = fileList;
		},
		uploadSuccess (response, file, fileList) {
			if (response.code == 1) {
				this.$message({
					message: "上传成功",
					type: "success"
				});
				console.log(response.rows[0]);
				//保存文件信息

				this.fileList = fileList;
				this.difDetailInfo = response.rows[0];
			} else {
				this.$alert("请求失败", {
					showClose: false,
					confirmButton: "确定",
					customClass: "alertFailure"
				});
				// this.$refs.upload.clearFiles();
			}
		},
		beforeAvatarUpload (file) {
			var fileType = file.name.substring(file.name.lastIndexOf('.') + 1)
			if (fileType != "txt" && fileType != "pdf" && fileType != "doc" && fileType != "docx" && fileType != "xls" && fileType != "xlsx") {
				this.$message({
					message: '上传文件类型只支持.txt/.pdf/.doc/.docx/.xls/.xlsx！',
					type: 'warning'
				});
				return false;
			}
			const size = file.size / 1024 / 1024 < 20;
			if (!size) {
				this.$message({
					message: '上传模板大小不能超过 20MB!',
					type: 'warning'
				});
				return false;
			}
		},
		saveData () {
			console.log("保存");
			if (this.mode == "add") {//新增页面,insert
				this.$refs["ruleForm"].validate((valid) => {
					if (valid == false) {
						return false;
					}

					var that = this;
					var obj = {};
					obj.id = ""//主键
					obj.purOrdNo = this.ruleForm.purOrdNo;//采购订单号
					obj.purOrdMxNo = this.ruleForm.purOrdMxNo;//采购订单行号
					obj.matCode = this.ruleForm.matCode;//物料编码
					obj.matName = this.ruleForm.matName;//物料描述
					obj.orderAmount = this.ruleForm.orderAmount;//订单数量
					obj.unitCode = this.ruleForm.unitCode;//单位
					obj.unitPrice = this.ruleForm.unitPrice;//订单单价
					obj.unitmoney = this.ruleForm.unitmoney;//订单金额
					obj.realPrice = this.ruleForm.realPrice;//实际单价
					obj.realMoney = this.ruleForm.realMoney;//实际金额
					obj.remark = this.ruleForm.remark;//备注
					if (this.fileList == "" || this.fileList == null) {
						obj.attachmentName = '';
						obj.url = '';
					}
					else {
						obj.attachmentName = this.fileList[0].name;
						obj.url = this.fileList[0].url;
					}

					obj.state = 0;//新增页面   保存   单据状态为新增
					obj.delFlag = 0//新增页面   保存   显示状态为启用

					obj.creatorId = this.$global.user.id;//创建人ID
					obj.creator = this.$global.user.employeeName;//创建人

					_Api.insertAdjustbill(obj).then(function (response) {
						var data = response.data;

						if (data.code == "1") {
							that.$message({
								message: "保存成功",
								type: "success"							});
							that.dialogVisible = false;
							that.search();
						}
						else {

							that.$alert(data.info, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"							});
						}
					})
						.catch(() => {
							that.$alert("请求失败！", {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"							});
						});
				});


			}
			else {//编辑页面
				this.$refs["ruleForm"].validate((valid) => {
					if (valid == false) {
						return false;
					}

					var that = this;
					var obj = {};
					obj.id = this.ruleForm.id//主键
					obj.purOrdNo = this.ruleForm.purOrdNo;//采购订单号
					obj.purOrdMxNo = this.ruleForm.purOrdMxNo;//采购订单行号
					obj.matCode = this.ruleForm.matCode;//物料编码
					obj.matName = this.ruleForm.matName;//物料描述
					obj.orderAmount = this.ruleForm.orderAmount;//订单数量
					obj.unitCode = this.ruleForm.unitCode;//单位
					obj.unitPrice = this.ruleForm.unitPrice;//订单单价
					obj.unitmoney = this.ruleForm.unitmoney;//订单金额
					obj.realPrice = this.ruleForm.realPrice;//实际单价
					obj.realMoney = this.ruleForm.realMoney;//实际金额
					obj.remark = this.ruleForm.remark;//备注
					//   if (this.fileList == "" || this.fileList == null) {
					//     obj.attachmentName = '';
					//     obj.url = '';
					//   }
					//   else {
					//     obj.attachmentName = this.fileList[0].name;
					//     obj.url = this.fileList[0].url;
					//   }
					if (this.files.length > 0) {
						obj.attachmentName = this.files[0].name;
						obj.url = this.files[0].url;
					} else {
						if (Array.isArray(this.fileList) && this.fileList.length > 0) {
							obj.attachmentName = this.fileList[0].name;
							obj.url = this.fileList[0].url;
						} else {
							obj.attachmentName = '';
							obj.url = '';
						}
					}
					obj.state = 0;//编辑页面   保存   单据状态为新增
					obj.delFlag = 0//编辑页面   保存   显示状态为启用

					obj.modifyerId = this.$global.user.id;//修改人ID
					obj.modifyer = this.$global.user.employeeName;//修改人

					_Api.editAdjustbill(obj).then(function (response) {
						var data = response.data;

						if (data.code == "1") {
							that.$message({
								message: "保存成功",
								type: "success"							});
							that.dialogVisible = false;
							that.search();
						}
						else {
							that.$alert(data.info, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"							});
						}
					})
						.catch(() => {
							that.$alert("请求失败！", {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"							});
						});
				})

			}
		},
		btn_submit () {
			if (this.mode == "add") {//新增页面
				this.$refs["ruleForm"].validate((valid) => {

					if (valid == false) {
						return false;
					}

					var that = this;
					var obj = {};
					obj.id = ""//主键
					obj.purOrdNo = this.ruleForm.purOrdNo;//采购订单号
					obj.purOrdMxNo = this.ruleForm.purOrdMxNo;//采购订单行号
					obj.matCode = this.ruleForm.matCode;//物料编码
					obj.matName = this.ruleForm.matName;//物料描述
					obj.orderAmount = this.ruleForm.orderAmount;//订单数量
					obj.unitCode = this.ruleForm.unitCode;//单位
					obj.unitPrice = this.ruleForm.unitPrice;//订单单价
					obj.unitmoney = this.ruleForm.unitmoney;//订单金额
					obj.realPrice = this.ruleForm.realPrice;//实际单价
					obj.realMoney = this.ruleForm.realMoney;//实际金额
					obj.remark = this.ruleForm.remark;//备注
					if (this.fileList == "" || this.fileList == null) {
						obj.attachmentName = '';
						obj.url = '';
					}
					else {
						obj.attachmentName = this.fileList[0].name;
						obj.url = this.fileList[0].url;
					}

					obj.state = 1;//新增页面   提交   单据状态为提交
					obj.delFlag = 0//新增页面   提交   显示状态为启用

					obj.creator = this.$global.user.employeeName;//创建人
					obj.creatorId = this.$global.user.id;//创建人ID

					_Api.insertAdjustbill(obj).then(function (response) {
						var data = response.data;

						if (data.code == "1") {
							that.$message({
								message: "提交成功",
								type: "success"							});
							that.dialogVisible = false;
							that.search();
						}
						else {
							that.$alert(data.info, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"							});
						}
					})
						.catch(() => {
							that.$alert("请求失败！", {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"							});
						});

				})
			} else {//编辑页面
				this.$refs["ruleForm"].validate((valid) => {
					if (valid == false) {
						return false;
					}

					var that = this;
					var obj = {};
					obj.id = this.ruleForm.id//主键
					obj.purOrdNo = this.ruleForm.purOrdNo;//采购订单号
					obj.purOrdMxNo = this.ruleForm.purOrdMxNo;//采购订单行号
					obj.matCode = this.ruleForm.matCode;//物料编码
					obj.matName = this.ruleForm.matName;//物料描述
					obj.orderAmount = this.ruleForm.orderAmount;//订单数量
					obj.unitCode = this.ruleForm.unitCode;//单位
					obj.unitPrice = this.ruleForm.unitPrice;//订单单价
					obj.unitmoney = this.ruleForm.unitmoney;//订单金额
					obj.realPrice = this.ruleForm.realPrice;//实际单价
					obj.realMoney = this.ruleForm.realMoney;//实际金额
					obj.remark = this.ruleForm.remark;//备注
					//   if (this.fileList == "" || this.fileList == null) {
					//     obj.attachmentName = '';
					//     obj.url = '';
					//   }
					//   else {
					//     obj.attachmentName = this.fileList[0].name;
					//     obj.url = this.fileList[0].url;
					//   }
					if (this.files.length > 0) {
						obj.attachmentName = this.files[0].name;
						obj.url = this.files[0].url;
					} else {
						if (Array.isArray(this.fileList) && this.fileList.length > 0) {
							obj.attachmentName = this.fileList[0].name;
							obj.url = this.fileList[0].url;
						} else {
							obj.attachmentName = '';
							obj.url = '';
						}
					}
					obj.state = 1;//编辑页面   提交  单据状态为提交
					obj.delFlag = 0//编辑页面   提交   显示状态为启用

					obj.modifyerId = this.$global.user.id;//修改人ID
					obj.modifyer = this.$global.user.employeeName;//修改人
					_Api.editAdjustbill(obj).then(function (response) {

						var data = response.data;

						if (data.code == "1") {
							that.dialogVisible = false;
							that.search();
							that.$message({
								message: "提交成功",
								type: "success"							});
						}
						else {
							that.$alert(data.info, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"							});
						}
					})
						.catch(() => {
							that.$alert("请求失败！", {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"							});
						});
				})
			}
		},
		cancel () {
			console.log("取消");
			var that = this;
			this.$nextTick(_ => {
				that.$refs.ruleForm.clearValidate();
			});
			this.dialogVisible = false;
			this.search();
		},
		downLoadFile (item) {
			console.log(item)
			var group = ''
			if (item.url.indexOf('SRM') > -1) {
				group = 'SRM'
			} else if (item.url.indexOf('SIGN') > -1) {
				group = 'SIGN'
			} else if (item.url.indexOf('TEST') > -1) {
				group = 'TEST'
			} else if (item.url.indexOf('MES') > -1) {
				group = 'MES'
			}
			var obj = {
				viewPath: item.url,
				groupName: group,
				fileName: ''
			};
			downLoadFileFunc(obj, item.name)
			//   var that = this;
			//   _Api.downLoadFile(obj).then(function (response) {
			//     var data = response.data;
			//     if (data.code == "1") {
			//       if (data.total > 0) {
			//         console.log(data.rows[0].fileName);
			//         that.downLoad(item.name, data.rows[0].fileName);//data.rows[0].filename
			//       }
			//     }
			//   })
		},
		downLoad (filename, url) {

			var eleLink = document.createElement('a');
			eleLink.style.display = 'none';
			eleLink.setAttribute("href", url);   //文件下载地址
			eleLink.setAttribute("download", filename);  //download属性只能在同域实现
			// 触发点击
			document.body.appendChild(eleLink);
			eleLink.click();
			// 然后移除
			document.body.removeChild(eleLink);
		}
	}
}


</script>